#!/usr/bin/perl 
#===============================================================================
#
#         FILE: project.pl
#
#        USAGE: ./project.pl  
#
#  DESCRIPTION: 
#
#      OPTIONS: 根据用户参数，生成工程架构
# REQUIREMENTS: ---
#         BUGS: ---
#        NOTES: 此脚本不单独使用，而是作为makePro.sh脚本的子脚本存在
#       AUTHOR: HuiDong (C), HDong_work@126.com
#      COMPANY: Personal
#      VERSION: 1.0
#      CREATED: 2013年10月17日 16时43分47秒
#     REVISION: ---
#===============================================================================

use strict;
use warnings;
use File::Copy;


my $dir = $ARGV[0];
my $name = $ARGV[1];
my $date = `date`;
my $info = "Copyright by HuiDong <donghui19870714\@126.com>\n\nGenerated by : Project.pl\nDate : $date\n\n此工具仅供内部参考，严禁传播发布.\n\nNote:\n";


if (!(-e "$dir/$name")) {
	mkdir("$dir/$name", 0777) || die "Can not create directory $name\n";
	open FILE, ">$dir/$name/readme.txt";
	print FILE $info;
	open FILE1, "/usr/src/project/fileTree.txt";
	while (<FILE1>) {
		print FILE $_;	
	}
	close(FILE);
	close(FILE1);

	copy("/usr/src/project/Makefile.am.top", "$dir/$name/Makefile.am") || die "Can not copy Makefile.am.top\n";
	open FILE_NEW, ">$dir/$name/NEWS";
	close(FILE_NEW);
	open FILE_READ, ">$dir/$name/README";
	close(FILE_READ);
	open FILE_Chan, ">$dir/$name/ChangeLog";
	close(FILE_Chan);
	open FILE_AUT, ">$dir/$name/AUTHORS";
	close(FILE_AUT);
}

if (!(-e "$dir/$name/data")) {
	mkdir("$dir/$name/data", 0777) || die "Can not create directory data\n";
	open FILE, ">$dir/$name/data/readme.txt";
	print FILE $info;
	print FILE "实验数据集详细信息，包括训练数据集和测试数据集\n";
	close(FILE);
}

if (!(-e "$dir/$name/depend")) {
	mkdir("$dir/$name/depend", 0777) || die "Can not create directory depend\n";
	open FILE, ">$dir/$name/depend/readme.txt";
	print FILE $info;
	print FILE "以来的外部资源\n";
	close(FILE);
}

if (!(-e "$dir/$name/configs")) {
	mkdir("$dir/$name/configs", 0777) || die "Can not create directory configs\n";
	open FILE, ">$dir/$name/configs/readme.txt";
	print FILE $info;
	print FILE "系统全局配置文件\n";
	close(FILE);
}

if (!(-e "$dir/$name/scripts")) {
	mkdir("$dir/$name/scripts", 0777) || die "Can not create directory scripts\n";
	open FILE, ">$dir/$name/scripts/readme.txt";
	print FILE $info;
	print FILE "perl和shell脚本语言\n";
	close(FILE);
}

if (!(-e "$dir/$name/data/train")) {
	mkdir("$dir/$name/data/train", 0777) || die "Can not create directory train\n";
	open FILE, ">$dir/$name/data/train/readme.txt";
	print FILE $info;
	print FILE "数据集详细信息,该文件中应该包含以下详细信息\n";
	print FILE "\t\(1\)来源:\n\t详细信息:\(最好采用文件的形式\)\n\t\(2\)其它:\n";
	close(FILE);
}

if (!(-e "$dir/$name/data/test")) {
	mkdir ("$dir/$name/data/test", 0777) || die "Can not create directory test\n";
	open FILE, ">$dir/$name/data/test/readme.txt";
	print FILE $info;
	print FILE "数据集详细信息,该文件中应该包含以下详细信息\n";
	print FILE "\t\(1\)来源:\n\t详细信息:\(最好采用文件的形式\)\n\t\(2\)其它:\n";
	close(FILE);
}

if (!(-e "$dir/$name/analysis")) {
	mkdir ("$dir/$name/analysis", 0777) || die "Can not create directory analysis\n";
	open FILE, ">$dir/$name/analysis/readme.txt";
	print FILE $info;
	print FILE "实验结果分析，包含测试用例和测试报告\n";
	close(FILE);
}

if (!(-e "$dir/$name/analysis/result")) {
	mkdir ("$dir/$name/analysis/result", 0777) || die "Can not create directory result\n";
	open FILE, ">$dir/$name/analysis/result/readme.txt";
	print FILE $info;
	print FILE "实验结果\n";
	close(FILE);
}

if (!(-e "$dir/$name/model")) {
	mkdir ("$dir/$name/model", 0777) || die "Can not create directory model\n";

	open FILE, ">$dir/$name/model/readme.txt";
	print FILE $info;
	print FILE "模型文件，例如ML的模型文件\n";
	close(FILE);
}

if (!(-e "$dir/$name/doc")) {
	mkdir ("$dir/$name/doc", 0777) || die "Can not create directory doc\n";

	open FILE, ">$dir/$name/doc/readme.txt";
	print FILE $info;
	print FILE "帮助文档，需要填写High-Level-System_Design.doc和UserManual.doc\n";
	close(FILE);
}
if (!(-e "$dir/$name/doc/user-manual")) {
	mkdir ("$dir/$name/doc/user-manual", 0777) || die "Can not create directory user-manual\n";
	open(FILE, ">$dir/$name/doc/user-manual/readme.txt") || die "can not create file in $dir/$name/help/gdb\n";
	print FILE $info;
	close(FILE);
}

if (!(-e "$dir/$name/demo")) {
	mkdir ("$dir/$name/demo", 0777) || die "Can not create directory demo\n";
	open FILE, ">$dir/$name/demo/readme.txt";
	print FILE $info;
	print FILE "测试实例\n";
	close(FILE);
	copy("/usr/src/project/Makefile.am.pro", "$dir/$name/demo/Makefile.am") || die "Can not copy Makefile.am.bin\n";
}

if (!(-e "$dir/$name/demo/include")) {
	mkdir ("$dir/$name/demo/include", 0777) || die "Can not create directory include\n";
	open FILE, ">$dir/$name/demo/include/readme.txt";
	print FILE $info;
	print FILE "包含的头文件\n";
	close(FILE);
}

if (!(-e "$dir/$name/analysis/report")) {
	mkdir ("$dir/$name/analysis/report", 0777) || die "Can not create directory report\n";
	open FILE, ">$dir/$name/analysis/report/readme.txt";
	print FILE $info;
	print FILE "测试报告，请按照STestRe.doc进行填写\n";
	close(FILE);
}

if (!(-e "$dir/$name/analysis/case")) {
	mkdir ("$dir/$name/analysis/case", 0777) || die "Can not create directory case\n";
	open FILE, ">$dir/$name/analysis/case/readme.txt";
	print FILE $info;
	print FILE "测试用例，请按照STestCase.doc进行填写\n";
	close(FILE);
}

if (!(-e "$dir/$name/src")) {
	mkdir ("$dir/$name/src", 0777) || die "Can not create directory src\n";
	open(FILE, ">$dir/$name/src/readme.txt") || die "can not create file in $dir/$name/src\n";
	print FILE $info;
	close(FILE);

	copy("/usr/src/project/Makefile.am.lib", "$dir/$name/src/Makefile.am") || die "Can not copy Makefile.am.lib\n";
}

if (!(-e "$dir/$name/lib")) {
	mkdir ("$dir/$name/lib", 0777) || die "Can not create directory lib\n";
	open(FILE, ">$dir/$name/lib/readme.txt") || die "can not create file in $dir/$name/lib\n";
	print FILE $info;
	close(FILE);
	copy("/usr/src/project/Makefile.am.lib", "$dir/$name/lib/Makefile.am") || die "Can not copy Makefile.am.lib\n";
}

if (!(-e "$dir/$name/trash")) {
	mkdir ("$dir/$name/trash", 0777) || die "Can not create directory trash\n";

	open FILE, ">$dir/$name/trash/readme.txt";
	print FILE $info;
	print FILE "回收站，用来保存临时或中间文件，防止删除的文件无法找回\n";
	close(FILE);
}

if (!(-e "$dir/$name/include")) {
	mkdir ("$dir/$name/include", 0777) || die "Can not create directory include\n";
	open(FILE, ">$dir/$name/include/readme.txt") || die "can not create file in $dir/$name/include\n";
	print FILE $info;
	close(FILE);
}

if (!(-e "$dir/$name/def")) {
	mkdir ("$dir/$name/def", 0777) || die "Can not create directory def\n";
	open(FILE, ">$dir/$name/def/readme.txt") || die "can not create file in $dir/$name/def\n";
	print FILE $info;
	close(FILE);
}

if (!(-e "$dir/$name/training")) {
	mkdir ("$dir/$name/training", 0777) || die "Can not create directory def\n";
	open(FILE, ">$dir/$name/training/readme.txt") || die "can not create file in $dir/$name/training\n";
	print FILE $info;
	close(FILE);
}

if (!(-e "$dir/$name/help")) {
	mkdir ("$dir/$name/help", 0777) || die "Can not craete directory help\n";
	open FILE, ">$dir/$name/help/readme.txt";
	print FILE $info;
	print FILE "帮助文档，主要包含:\n";
	print FILE "\t\(1\) doxygen,自动生成帮组文档\n\t\(2\) gdb,调试工具\n";
	print FILE "\t\(3\) make, 项目组织工具\n";
	close(FILE);
}

if (!(-e "$dir/$name/help/doxygen")) {
	mkdir ("$dir/$name/help/doxygen", 0777) || die "Can not craete directory doxygen\n";
	open(FILE, ">$dir/$name/help/doxygen/readme.txt") || die "can not create file in $dir/$name/help/doxygen/\n";
	print FILE $info;
	close(FILE);
}

if (!(-e "$dir/$name/help/make")) {
	mkdir ("$dir/$name/help/make", 0777) || die "Can not craete directory make\n";
	open(FILE, ">$dir/$name/help/make/readme.txt") || die "can not create file in $dir/$name/help/make/\n";
	print FILE $info;
	close(FILE);
}

if (!(-e "$dir/$name/help/gdb")) {
	mkdir ("$dir/$name/help/gdb", 0777) || die "Can not craete directory gdb\n";
	
	open(FILE, ">$dir/$name/help/gdb/readme.txt") || die "can not create file in $dir/$name/help/gdb/\n";
	print FILE $info;
	close(FILE);
}

copy("/usr/src/project/Doxygen_sam.h", "$dir/$name/help/doxygen") || die "Can not copy Doxygen_sam.h\n";
copy("/usr/src/project/doxygen_Manual.pdf", "$dir/$name/help/doxygen") || die "Can not copy doxygen_Manual.pdf\n";
copy("/usr/src/project/gdb_Manual.txt", "$dir/$name/help/gdb") || die "Can not copy gdb_Manual.pdf\n";
copy("/usr/src/project/Makefile_Manual", "$dir/$name/help/make") || die "Can not copy Makefile_Manual\n";
copy("/usr/src/project/User-Manual.txt", "$dir/$name/doc/user-manual") || die "Can not copy user-manual\n";
copy("/usr/src/project/Automake.pdf", "$dir/$name/help/make") || die "Can not copy Automake\n";
copy("/usr/src/project/automake-sample.tar", "$dir/$name/help/make") || die "Can not copy automake-sample.tar\n";
copy("/usr/src/project/STestCase.doc", "$dir/$name/analysis/case") || die "Can not copy STestCase\n";
copy("/usr/src/project/STestRe.doc", "$dir/$name/analysis/report") || die "Can not copy STestRe\n";
copy("/usr/src/project/High-Level_System_Design.doc", "$dir/$name/doc") || die "Can not copy High-Level_System_Design\n";
copy("/usr/src/project/UserManual.doc", "$dir/$name/doc") || die "Can not copy UserManual.doc\n";
